<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/jsp/base/taglibs.jsp"%>
<%@include file="/WEB-INF/jsp/base/head.jsp"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="<%=request.getContextPath()%>/css/lightBox.css" rel="stylesheet" type="text/css"/>
<title>系统用户列表</title>
</head>
<body>

<div class="center_main">
	<div id="btn-option">
        <a class="add-btn"  id="popAdd" href="javascript:void(0)" title="新增用户">新增</a>
  		<a class="edit-btn" id="popEdit"   href="javascript:void(0)" title="修改用户">修改</a>
  		<a class="del-btn"  id="delete" href="javascript:void(0)" title="删除用户">删除</a>
  		<a class="enable-btn"  id="enabled"     href="javascript:void(0);" title="启用">启用</a>
		<a class="disable-btn"  id="disabled"     href="javascript:void(0);" title="禁用">禁用</a>
	</div>
	<div class="center_left"></div>
</div>

  <div id="page-top">
  	<span>系统用户管理列表</span>
  	<b></b><i></i>
  </div>
  
<div id="page">
    <s:form id="form1" name="form1" namespace="/system" method="post">
    
    <input type="hidden" id="delURL" value="userAction!userDelete.do" />
    <input type="hidden" id="enabledURL" value="system/userAction!enabled.do" />
    <input type="hidden" id="disabledURL" value="system/userAction!disabled.do" />
    <input type="hidden" id="returnURL" value="system/userAction!getUserList.do" />
    
    <div id="search">
		<div class="search-edit-wapper">
			<label for="">登陆名：</label>
	   		<input type="text"  class="form-text" name="usersBizBean.userName" value="<s:property value='usersBizBean.userName'/>" />
		</div>
		<div class="search-edit-wapper">
			<label for="">真实名称：</label>
	   		<input type="text"  class="form-text" name="usersBizBean.realName" value="<s:property value='usersBizBean.realName'/>" />
		</div>
	</div>
			
	<div id="search-btn-wapper">
		<s:submit cssClass="btn"  method="getUserList" value="查询" id="btnEnter"></s:submit>
	</div>
			
	<div id="item-list">
		<table>
			<thead>
				<tr>
					<th>选择<input type="checkbox" id="selectAll" /></th>
					<th>序号</th>
					<th>登陆名</th>
					<th>真实名称</th>
					<th>邮箱</th>
					<th>状态</th>
					<th>创建时间</th>
					<th>备注</th>
				</tr>
			</thead>
	   		<tbody>
				<s:iterator value="usersBizBeanList" status="sta"> 
				<tr>
					<td><input type="checkbox" name="usersBizBeanList[<s:property value="#sta.index+1"/>].userId" class="classCheckbox" value="<s:property value="userId"/>" /></td>
					<td><s:property value="#sta.index+1"/></td>
					<td><s:property value="userName"/></td>
					<td><s:property value="realName"/></td>
					<td><s:property value="email"/></td>
					<td><d:codeItem name="use_yes_no" value="${status}"></d:codeItem></td>
					<td><s:date name="%{createdDate}" format="yyyy-MM-dd HH:mm:ss"></s:date></td>
					<td><s:property value="remark"/></td>
				</tr>
				</s:iterator>
				<s:if test="%{usersBizBeanList.size() == 0}">
				    <tr>
				       <td colspan="7"><span class="spanRB">没有数据!</span></td>
				    </tr>
				</s:if>
			</tbody>
		</table>
	</div>
  	</s:form>
</div>
<div id="page-bottom">
	<b></b><i></i>
	<d:page namespace="/system" action="userAction!getUserList">
	</d:page>
</div>
</body>

<script src="<%=request.getContextPath()%>/js/lightBox.js" type='text/javascript'></script>
<script type="text/javascript">
$(function(){
	$("#popAdd").click(function(){
		var body = '<form action="userAction!save.do" id="userform" name="userform" method="post">' +
		'<div class="row"><b class="label">登陆名：</b><input name="userName" id="userName" class="input" />&nbsp;&nbsp;<font color="red" id="message_userName">*</font></div>' +		
		'<div class="row"><b class="label">密&nbsp;&nbsp;码：</b><input type="password" name="passWord" id="passWord" class="input" />&nbsp;&nbsp;<font color="red" id="message_passWord">*</font></div>'+
		'<div class="row"><b class="label">密码确认：</b><input type="password" name="confirmPasswrok" id="confirmPasswrok" class="input" />&nbsp;&nbsp;<font color="red" id="message_confirmPasswrok">*</font></div>'+
		'<div class="row"><b class="label">真实名称：</b><input name="realName" id="realName" class="input" />&nbsp;&nbsp;<font color="red" id="message_realName">*</font></div>'+
		'<div class="row"><b class="label">电子邮箱：</b><input name="email" id="email" class="input" />&nbsp;&nbsp;<font color="red" id="message_email"></font></div>'+
		'<div class="row"><b class="label">备注:</b><textarea name="userRemark" id="userRemark" rows="3" class="input" style="textmode:multiline;" onkeydown="if (this.value.length>=200){event.returnValue=false}"></textarea></div>' +
		'</form>';
	var	footer='<div style="text-align:center"><input type="button" value="保存" class="divbtn" id="savaBtn"/><input type="button" value="取消" class="divbtn" id="usercancel" /></div>';
	Box("user",500,300,body,"新建用户",footer);
	});
	
	$("#savaBtn").live("click",function(){
		
		var userName = $("#userName").val();
		var passWord = $("#passWord").val();
		var confirmPasswrok = $("#confirmPasswrok").val();
		var realName = $("#realName").val();
		if(userName.length == 0 ){
			$("#message_userName").html("登陆名不能为空！");
			$("#userName").focus();
			return false;
		} else {
			$("#message_userName").html("*");
		}
		if(passWord.length == 0){
			$("#message_passWord").html("密码不能为空！");
			$("#passWord").focus();
			return false;
		} else {
			$("#message_passWord").html("*");
		}
		if(confirmPasswrok.length == 0){
			$("#message_confirmPasswrok").html("密码确认不能为空！");
			$("#confirmPasswrok").focus();
			return false;
		} else {
			$("#message_confirmPasswrok").html("*");
		}
		if(confirmPasswrok != passWord){
			$("#message_confirmPasswrok").html("密码输入的不一致！");
			$("#confirmPasswrok").select();
			return false;
		} else {
			$("#message_confirmPasswrok").html("*");
		}
		if(realName.length == 0){
			$("#message_realName").html("真实名称不能为空！");
			$("#realName").focus();
			return false;
		} else {
			$("#message_realName").html("*");
		}
		
		
		$.ajax({
			   type: "POST",
			   url: "<%=request.getContextPath()%>/system/userAction!userAdd.do",
			   data:{'usersBizBean.userName':userName,
				     'usersBizBean.passWord':passWord,
				     'usersBizBean.confirmPasswrok':confirmPasswrok,
					 'usersBizBean.realName':realName,
					 'usersBizBean.email':$("#email").val(),
					 'usersBizBean.remark':$("#userRemark").val()
				    },
			   dataType: "json",
			   async: false,
			   success: function(msg){
					   if(null == msg){
				   			alert("新增用户失败！");
				   			return null;
				   		}
						if(msg.userName !=''){
							$("#message_userName").html(msg.userName);
						}
						if(msg.passWord != ''){
							$("#message_passWord").html(msg.passWord);
						} 
						if(msg.confirmPasswrok != ''){
							$("#message_confirmPasswrok").html(msg.confirmPasswrok);
						}
						if(msg.realName != ''){
							$("#message_realName").html(msg.realName);
						} 
						if(msg.email != ''){
							$("#message_email").html(msg.email);
						}
						alert("新增用户成功！");
						$("#form1").attr("action", $("#returnURL").val());
						$("#form1").submit();   
			   	}
			});
		
	});
	
	$("#popEdit").click(function(){
		
		var obj = $("input[type=checkbox]:checked.classCheckbox");
		var item = obj.length;
		if(item != undefined &&  item > 0 && item == 1) {
			$.ajax({
				   type: "POST",
				   url: "<%=request.getContextPath()%>/system/userAction!getUserEdit.do",
				   data:{'usersBizBean.userId':obj.val()},
				   dataType: "json",
				   async: false,
				   success: function(userBizBean){
							if(userBizBean != null){
								
								var body = '<form id="userform" name="userform" method="post">' +
								'<div class="row"><b class="label">登陆名：</b><input name="userName" id="userName" readonly="readonly" style="background-color: #DDDDDD;border: 0px;" class="input"  value='+userBizBean.userName+' />&nbsp;&nbsp;<font color="red" id="message_userName">*</font><input type="hidden" name="userId" id="userId" value= "'+userBizBean.userId+'"/></div>' +		
								'<div class="row"><b class="label">密&nbsp;&nbsp;码：</b><input type="password" name="passWord" value='+userBizBean.passWord+' id="passWord" class="input" />&nbsp;&nbsp;<font color="red" id="message_passWord">*</font></div>'+
								//'<div class="row"><b class="label">密码确认：</b><input type="password" name="confirmPasswrok" id="confirmPasswrok" class="input" value='+userBizBean.confirmPasswrok+' />&nbsp;&nbsp;<font color="red" id="message_confirmPasswrok">*</font></div>'+
								'<div class="row"><b class="label">真实名称：</b><input name="realName"  value='+userBizBean.realName+' id="realName" class="input" />&nbsp;&nbsp;<font color="red" id="message_realName">*</font></div>'+
								'<div class="row"><b class="label">电子邮箱：</b><input name="email" id="email" class="input" value='+userBizBean.email+'>&nbsp;&nbsp;<font color="red" id="message_email"></font></div>'+
								'<div class="row"><b class="label">备注:</b><textarea name="userRemark" id="userRemark" rows="3" class="input" value='+userBizBean.remark+' style="textmode:multiline;" onkeydown="if (this.value.length>=200){event.returnValue=false}"></textarea></div>' +
								'</form>';
							var	footer='<div style="text-align:center"><input type="button" value="保存" class="divbtn" id="editBtn"/><input type="button" value="取消" class="divbtn" id="usercancel" /></div>';
							Box("user",500,300,body,"修改用户",footer);
							}
				   }
				});
		} else if(item == undefined || item <= 0 ) {
			alert("您还没有选择数据!");
			return false;
		} else {
			alert("您只能选择一条数据!");
			return false;
		}
	});
	$("#editBtn").live("click", function(){
		
		var userId = $("#userId").val();
		var userName = $("#userName").val();
		var passWord = $("#passWord").val();
		var realName = $("#realName").val();
		
		if(userName.length == 0 ){
			$("#message_userName").html("登陆名不能为空！");
			$("#userName").focus();
			return false;
		} else {
			$("#message_userName").html("*");
		}
		if(passWord.length == 0){
			$("#message_passWord").html("密码不能为空！");
			$("#passWord").focus();
			return false;
		} else {
			$("#message_passWord").html("*");
		}
		if(realName.length == 0){
			$("#message_realName").html("真实名称不能为空！");
			$("#realName").focus();
			return false;
		} else {
			$("#message_realName").html("*");
		}
		
		$.ajax({
			   type: "POST",
			   url: "<%=request.getContextPath()%>/system/userAction!userEdit.do",
			   data:{'usersBizBean.userId':userId,
				     'usersBizBean.userName':userName,
				     'usersBizBean.passWord':passWord,
					 'usersBizBean.realName':realName,
					 'usersBizBean.email':$("#email").val(),
					 'usersBizBean.remark':$("#userRemark").val()
				    },
			   dataType: "json",
			   async: false,
			   success: function(msg){
				   		if(null == msg){
				   			alert("修改用户失败！");
				   			return null;
				   		}
						if(msg.userName !=''){
							$("#message_userName").html(msg.userName);
						} 
						if(msg.passWord != ''){
							$("#message_passWord").html(msg.passWord);
						} 
						if(msg.confirmPasswrok != ''){
							$("#message_confirmPasswrok").html(msg.confirmPasswrok);
						} 
						if(msg.realName != ''){
							$("#message_realName").html(msg.realName);
						} 
						if(msg.email != ''){
							$("#message_email").html(msg.email); 
						}
						alert("修改用户成功！");
						$("#form1").attr("action", $("#returnURL").val());
						$("#form1").submit(); 
			   }
			});
	});
});
</script>
</html>